<?php
use backend\models\GrpClass;
use backend\models\GrpImageType;
use yii\helpers\Url;
use backend\models\PrfType;
use yii\widgets\ActiveForm;
use yii\helpers\Html;
use backend\assets\FontawesomeAsset;

FontawesomeAsset::register($this);
$this->title =  '图片管理';
$img_tag = isset($_GET['tag'])?$_GET['tag']:'img_id';
$previous = Url::previous();

 
?>

<style type="text/css">
list-style:none;
</style>

	  <link rel="stylesheet" type="text/css" class="library" href="tree_depends/bootstrap-2.2.1.min.css"> 
	<script type="text/javascript" class="library" src="tree_depends/jquery-1.7.2.min.js"></script>
	<script type="text/javascript" class="library" src="tree_depends/bootstrap-2.2.1.min.js"></script>
<script type="text/javascript">
<!--
//新增点击分类名称 查询分类图片路径

function get_url(id){
	$("#show_img_id").val(id);
	$("#upload_img_typeid").val(id);
	$("#del_img_id").val(id);
	 $.ajax({url:'index.php?r=taozhuang-new/search-addr',
		  data:{"id":id},
		  success:function(addr){
			 
			  addr="images/"+addr;
			 
			  if(addr!=""){
				 
				  $("#img_url").val(addr);
			  } 
		  },error:function(){
				alert('error..');
		  }
	 });
	 
		if(!tag){
			tag='type';
		}
		img_type_click = search;
		img_tag = tag;
		$.ajax({
			//type: "POST",
			url: 'index.php?r=image/show-image',
			data: {"page":page-1,"search":search,"tag":tag},
			dataType: 'json',
			beforeSend:function(){
				$("#list ul").append("<li id='loading'>loading...</li>");
				},
			success:function(json){
				//alert(json);
				$("#list ul").empty(); //清空数据区
				total = json.total; //总记录数
				pageSize = json.pageSize;//每页显示条数
				curPage = page;//当前页
				totalPage = json.totalPage;//总页数
				var li ="";
				if( json.list != "" )
				{
					var list = json.list;
					var have;
					$.each(list,function(index,array){
						
						li += "<li><input name='choose_img' type='checkbox'  value='" + array['id'] +"'/><img src='" + array['url'] +"' height='"+ array['height'] +"' width='" + array['width'] + "'>"  + array['id']+": "+array['name']+"_"+array['height']+"X"+array['width']+"<button onclick='update_img("+ array['id']+")'>重新上传图片</button></li>";
						have = array['url']; 
						});
						if(have.length != 0){
						$("#list ul").append(li);}
				}
				else{ 
					$("#list ul").append("<li>暂无图片</li>");
					}
				},
			complete:function(){
					getPageBar();
				},
			error:function(){
					alert("数据加载失败");
				}, 
			});
}
  
//点击新增类型
function add_type(){
	var show_img_id=$("#show_img_id").val();
	if(show_img_id==-2){
		alert("分类表不可添加");
    }else{
        	if(show_img_id!=""&&show_img_id!=0){
        		$("#operation_img").hide();
        		$("#add_type_div").show();
        	}else{
        		alert("不可新增分类");
        	}
    }
    
}
//上传图片到当前目录
function upload_img(){
	var upload_img_typeid=$("#upload_img_typeid").val();
	if(upload_img_typeid<0){
		alert("当前目录不可添加图片");
    }else{
        	if(upload_img_typeid!=""&&upload_img_typeid!=0){
        		//跳转上传图片 传递分类id
        		var  url = "index.php?r=image/upload-flash-image&type_id="+upload_img_typeid;
        		window.location.href=url;
        		//window.open(url ,'','width=800,height=600,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes');
        	}else{
        		alert("不可新增分类");
        	}
    }
}
//关闭添加类型
function addtype_hide(){

	$("#operation_img").show();
	$("#add_type_div").hide();
	
}

//点击新增类型 开始操作数据
function addtype_data(){
	var show_img_id=$("#show_img_id").val();
	if(show_img_id!=""&&show_img_id!=0){
		 var addr=$("#new_addr").val();
		 var addold=$("#new_addr").val();
			var type=$("#new_typename").val();
			var firstaddr= $("#img_url").val();
			addr=firstaddr+"/"+addr;
			if(addr!=""&&type!=""){
				$.ajax({url:'index.php?r=taozhuang-new/add-addr',
						data:{"addr":addr,
							 "typename":type,
							 "show_img_id":show_img_id,
							 "addold":addold
						},
						success:function(){
							window.location.reload();
						}
				});
			} 
	}else{
		alert("不可新增分类");

		}
   

}

//删除类型
function del_type(){
	var del_img_id=$("#del_img_id").val();

	if(del_img_id==-2){
		alert("分类表不可删除");
    }else{
        	if(del_img_id!=""&&del_img_id!=0){
        		$.ajax({url:'index.php?r=taozhuang-new/del-addr',
        			data:{"id":del_img_id},
        			success:function(){
        		 		window.location.reload();
        			}
        		});
           }else{
    
           		alert("没获取到typeid，请重试!");
          }
    }
}
//删除选中图片
function del_img(){
    var id_str="";
    $("input[name='choose_img']").each(function(){
        //判断复选框是否选中，如果选中 获取图片id 
    	var check_state=$(this).is(":checked");
    	var id=0;
    	
    	if(check_state){
    		id=$(this).val();
    		id_str+=id+",";
    	}
    });
	if(id_str==""){
		alert("请选择图片!");
	}else{
		$.ajax({
    				url:'index.php?r=image/del-image',
    				data:{'ids':id_str},
    				success:function(code){
    						  window.location.reload();
    				}
			 });
	}
	
}
//设置选中的图片为show底图
function up_show_img(){
	  var id=0;
	  var show_id=$("#show_id").val();
	  var url='index.php?r=show/img-update&id='+show_id;
      if(show_id==0){
			alert("请到秀家页面确定秀家再操作底图!");
      }else{
        	  $("input[name='choose_img']").each(function(){
        	        //判断复选框是否选中，如果选中 获取图片id 
        	    	var check_state=$(this).is(":checked");
        	    	if(check_state){
        	    		id=$(this).val();
        	    	}
        	    });
                if(id==0){
            	   alert("请选择图片");
                }else{
                	$.ajax({
                			url:'index.php?r=show/update-image',
                			data:{'id':id,'show_id':show_id},
                			success:function(code){
                				window.location.href=url;

                        				 
                			}
            		 });
                }
      }
}

/**
 * 从图  添加
 */
  function up_vrpos_img(){
    var id=0;
    var vr_pos_id=$("#vr_pos_id").val();
    var tzid=<?=$tzid?>;
    var type=<?=$type?>;
    if(vr_pos_id==0&&type==2){
        alert("请选择了vr再来操作图片!");
    }else{
        $("input[name='choose_img']").each(function(){
            //判断复选框是否选中，如果选中 获取图片id
            var check_state=$(this).is(":checked");
            if(check_state){
                id=$(this).val(); 
            }
        });
        
        if(id==0){
            alert("请选择图片");
        }else{
            //主图 添加
            if(type==1){
                $.ajax({
                    url:'index.php?r=vr/update-image-main',
                    data:{'id':id,'tzid':tzid},
                    success:function(code){
                        var url='index.php?r=vr/vr-img-op&tzid='+tzid;
                        window.location.href=url;
                    }
                });
            //从图 添加    
            }else if(type==2){
                $.ajax({
                    url:'index.php?r=vr/update-image-other',
                    data:{'id':id,'vr_id':vr_pos_id},
                    success:function(code){
                        var url='index.php?r=vr/vr-img-op&tzid='+tzid;
                       // window.history.go(-1);
                        window.location.href=url;
                    }
                });
		    //替换
            }else if(type==3){
               	 $.ajax({
                     url:'index.php?r=vr/replace-image-main',
                     data:{'id':id,'vr_id':vr_pos_id},
                     success:function(code){
                         var url='index.php?r=vr/vr-img-op&tzid='+tzid;
                         window.location.href=url;
                     }
                 });
            //插入     
            }else if(type==4){
               	 $.ajax({
                     url:'index.php?r=vr/insert-image-main',
                     data:{'id':id,'vr_id':vr_pos_id},
                     success:function(code){
                         var url='index.php?r=vr/vr-img-op&tzid='+tzid;
                         window.location.href=url;
                     }
                 });
            }
        }
    }
}
//重新上传图片
function new_show_img(){
	   
	  var show_id=$("#show_id").val();
	  var upload_img_typeid=$("#upload_img_typeid").val();
      if(show_id==0||upload_img_typeid==""||upload_img_typeid==0){ 
			alert("请到秀家页面确定秀家再操作底图!");
      }else{
          var url='index.php?r=image/upload-flash-image-show&showid='+show_id+'&type_id='+upload_img_typeid;
          window.location.href=url;
      }

	
}
//重新上传vr图片
function new_vrpos_img(){
	 	var vr_pos_id=$("#vr_pos_id").val();
	    var tzid=<?=$tzid?>;
	    var type=<?=$type?>;
	    var upload_img_typeid=$("#upload_img_typeid").val();
	    if(vr_pos_id==0&&(type==2||type==3)){
	        alert("请选择了vr再来操作图片!");
	    }else if(upload_img_typeid==""||upload_img_typeid==0){
			 alert("请选择分类!");
	     //替换图片    
		 }else{
	    	 var url='index.php?r=image/upload-flash-image-vr&type='+type+'&vr_pos_id='+vr_pos_id+'&tzid='+tzid+'&type_id='+upload_img_typeid;
	    	 window.location.href=url;
		} 

	
}
//查询当前数据
var curPage = 1;
var total,pagesize,totalPage;
var img_type_click;
var img_tag
//获取当前页数据
function getData(page,search,tag){
	//设置当前选中菜单的id
	$("#show_img_id").val(search);
	$("#upload_img_typeid").val(search);
	$("#del_img_id").val(search);
 $.ajax({url:'index.php?r=taozhuang-new/search-addr',
		  data:{"id":search},
		  success:function(addr){
				addr="images/"+addr; 
			 	if(addr!=""){
				 	$("#img_url").val(addr);
			 	} 
			 
		  }
	 });
	
	 
	if(!tag){
		tag='type';
	}
	img_type_click = search;
	img_tag = tag;
	$.ajax({
		//type: "POST",
		url: 'index.php?r=image/show-image',
		data: {"page":page-1,"search":search,"tag":tag},
		dataType: 'json',
		beforeSend:function(){
			$("#list ul").append("<li id='loading'>loading...</li>");
			},
		success:function(json){
			//alert(json);
			$("#list ul").empty(); //清空数据区
			total = json.total; //总记录数
			pageSize = json.pageSize;//每页显示条数
			curPage = page;//当前页
			totalPage = json.totalPage;//总页数
			var li ="";
			if( json.list != "" )
			{
				var list = json.list;
				var have;
				$.each(list,function(index,array){
					
					li += "<li><input name='choose_img' type='checkbox'  value='" + array['id'] +"'/><img src='" + array['url'] +"' height='"+ array['height'] +"' width='" + array['width'] + "'>"  + array['id']+": "+array['name']+"_"+array['height']+"X"+array['width']+"<button onclick='update_img("+ array['id']+")'>重新上传图片</button></li>";
					have = array['url']; 
					});
					if(have.length != 0){
					$("#list ul").append(li);}
			}
			else{ 
				$("#list ul").append("<li>暂无图片</li>");
				}
			},
		
		complete:function(){
				getPageBar();
			},
		error:function(){
				alert("数据加载失败");
			}, 
		});
}
//三级getdata
//获取当前页数据
function getData3(page,search,tag){
	$("#show_img_id").val(0);
	$("#upload_img_typeid").val(search);
	$("#del_img_id").val(search);
 $.ajax({url:'index.php?r=taozhuang-new/search-addr',
		  data:{"id":search},
		  success:function(addr){
				addr="images/"+addr; 
			 	if(addr!=""){
				 	$("#img_url").val(addr);
			 	} 
			 
		  }
	 });
	
	 
	if(!tag){
		tag='type';
	}
	img_type_click = search;
	img_tag = tag;
	$.ajax({
		//type: "POST",
		url: 'index.php?r=image/show-image',
		data: {"page":page-1,"search":search,"tag":tag},
		dataType: 'json',
		beforeSend:function(){
			$("#list ul").append("<li id='loading'>loading...</li>");
			},
		success:function(json){
			//alert(json);
			$("#list ul").empty(); //清空数据区
			total = json.total; //总记录数
			pageSize = json.pageSize;//每页显示条数
			curPage = page;//当前页
			totalPage = json.totalPage;//总页数
			var li ="";
			if( json.list != "" )
			{
				var list = json.list;
				var have;
				$.each(list,function(index,array){
					li += "<li><input name='choose_img' type='checkbox'  value='" + array['id'] +"'/><img src='" + array['url'] +"' height='" + array['height'] +"' width='" + array['width'] + "'>"  + array['id']+": "+ array['name']+"<br/>_"+array['height']+"X"+array['width']+"</li>";
					
					have = array['url'];
					});
					if(have.length != 0){
					$("#list ul").append(li);}
			}
			else{
				$("#list ul").append("<li>暂无图片</li>");
				}
			},
		
		complete:function(){
				getPageBar();
			},
		error:function(){
				alert("数据加载失败");
			},
		});
}
function getPageBar(){
	//页码大于最大页数，确认当前页
	if(curPage > totalPage) curPage=totalPage;
	//页码小于1，确认当前页
	if(curPage<1) curPage = 1;
	
	pageStr = "<span>共"+total+"条</span><span>"+curPage+"/"+totalPage+"</span>";
	
	//如果是第一页
	if(curPage ==1){
		pageStr += "<span>首页</span><span>上一页</span> ";
	}else{
		pageStr += "<span><a href='javascript:void(0)' rel='1'>首页</a></span><span><a href='javascript:void(0)' rel='"+(curPage-1)+"'>上一页</a></span> "; 
	}
	
	//如果是最后页
	if(curPage>=totalPage){ 
    	pageStr += "<span>下一页</span><span>尾页</span></div>跳转到 <input id='p_index' style='width:30px;' />页<button onclick='p_search()'>Go</button>"; 
  	}else{ 
    	pageStr += "<span><a href='javascript:void(0)' rel='"+(parseInt(curPage)+1)+"'> 下一页</a></span><span><a href='javascript:void(0)' rel='"+totalPage+"'>尾页</a> </span>跳转到 <input id='p_index' style='width:30px;' />页<button onclick='p_search()'>Go</button>"; 
  } 
      
  $("#pagecount").html(pageStr); 

}
//点击跳转到某一页
function p_search(){

	 var rel = $("#p_index").val(); 
	    if(rel){ 
	      getData(rel,img_type_click,img_tag); 
	    } 
}
//打开页面，第一次加载
$(function(){ 
  getData(1,101000000,'type'); 
  $("#pagecount span a").live('click',function(){ 
    var rel = $(this).attr("rel"); 
    if(rel){ 
      getData(rel,img_type_click,img_tag); 
    } 
  }); 
}); 

function show(id)
{
	$("#upload_img"+id).css("display","inline");
}
function hide(id)
{
	$("#upload_img"+id).css("display","none");
}

 
function check_img(obj,id)
{
	 
	if(obj.checked)
	{	
		$("#upload_img"+id).css("display","inline");
	}
	else
	{
		$("#upload_img"+id).css("display","none");
	}
}
//修改图片
function update_img(id){
var url='index.php?r=image/flash-update-image&id='+id;
window.open(url);
}
//-->
</script>

<body>


<?php $url = "index.php?r=image/upload-flash-image&type_id="; ?>
	<div class="tree well" style='float:left;width:20%;'>
	

	
	<?php 
		function tree_show($father)
		{
			$url = "index.php?r=image/upload-image&type_id=";
			$model_tree = PrfType::findAll(['father'=>$father]);
			if ($model_tree != null)
			{
				foreach ($model_tree as $value)
				{
					echo '<ul>';
					echo '<li style="display:none;">';
						$model_tree_child = PrfType::findAll(['father'=>$value->id]);
						if($model_tree_child != null)
						{
							//echo '<input onclick="check_img('.$value->id.')" type="checkbox" value="'.$value->id.'"/><span onmouseover="show('.$value->id.')" onmouseout="hide('.$value->id.')"><i class="icon-plus-sign"></i><a href="#" onclick="getData(1,'.$value->id.')"> '.$value->typename.'</a></span><br/><span style="display:none;cursor:pointer" id="upload_img'.$value->id.'" onclick="upload_img()" onmouseover="show('.$value->id.')" onmouseout="hide('.$value->id.')">上传图片</span>';
							echo '<input id="check_img('.$value->id.')" onclick="check_img(this,'.$value->id.')" type="checkbox" value="'.$value->id.'"/><span><i class="icon-plus-sign"></i><a href="#" onclick="getData(1,'.$value->id.',\'type\')"> '.$value->typename.'</a></span><br/><span style="display:none;cursor:pointer;" id="upload_img'.$value->id.'" onclick="javascript:window.open(\''.$url.$value->id.'\',\'\',\'width=800,height=600,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes\')">上传图片</span>';
								
							tree_show($value->id);
						}
						else if($model_tree_child == null)
						{
							//echo '<a href="#" onclick="getData(1,'.$value->id.')"><span onmouseover="show('.$value->id.')" onmouseout="hide('.$value->id.')" onclick="show_image('.$value->id.')">'.$value->typename.'</span></a><br/><span style="display:none" id="upload_img'.$value->id.'" onclick="upload_img()" onmouseover="show('.$value->id.')" onmouseout="hide('.$value->id.')"><input style="width:100%;" type="file"/></span>';
							echo '<input id="check_img('.$value->id.')" onclick="check_img(this,'.$value->id.')" type="checkbox" value="'.$value->id.'"/><a href="#" onclick="getData(1,'.$value->id.',\'type\')"><span onclick="show_image('.$value->id.')">'.$value->typename.'</span></a><br/><span style="display:none;cursor:pointer;" id="upload_img'.$value->id.'" onclick="javascript:window.open(\''.$url.$value->id.'\',\'\',\'width=800,height=600,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes\')">上传图片</span>';
								
						}
						
					echo '</li>';
					echo '</ul>';
				}
			}		
		}
		?>


		地址：<input id="img_url" value="images/newtaozhuang"  style="width:370px;"/>
	<!-- 新套装开始 -->	
 
		<li>
		<span>
			<a href="#" onclick="getData(1,200,'type')"><i class="icon-folder-open"></i>新套装</a>
			</span>
			<!-- 新算法开始 -->
			
			<?php for($a=0;$a<count($newtaozhuang_list2);$a++):?>
            		<ul>
            			<li>			 
            				<span><i class="icon-minus-sign"></i> 
            					<a href="#" onclick="getData(1,<?=$newtaozhuang_list2[$a]["id"]?>,'type')"><?=$newtaozhuang_list2[$a]["typename"]?></a>
            				</span>  
            				<!-- 
            				<span style=" cursor:pointer;" id="upload_img<?=$newtaozhuang_list2[$a]["id"]?>" onclick="javascript:window.open(<?="'".$url.$newtaozhuang_list2[$a]["id"]."'"?> ,'width=800,height=600,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes')">上传图片</span> 
                          
            				 -->                
            				<?php for($b=0;$b<count($newtaozhuang_list2[$a]["child"]);$b++):?>
            				<ul>
            					
            					<?php if(count($newtaozhuang_list2[$a]["child"][$b]["child"])>0):?>
            							 <li>
            							 <!-- <input id='check_img(<?=$newtaozhuang_list2[$a]["child"][$b]["id"]?>)' onclick='check_img(this,<?=$newtaozhuang_list2[$a]["child"][$b]["id"]?>)' type="checkbox" value="<?=$newtaozhuang_list2[$a]["child"][$b]["id"]?>" >
                                           -->
							 				  <span title="Collapse this branch" data-addr="<?=$newtaozhuang_list2[$a]["child"][$b]["id"]?>">
                                            	<i class="icon-plus-sign"></i>
                                            	 <a href="#" onclick="getData(1,<?=$newtaozhuang_list2[$a]["child"][$b]["id"]?>,'type')"> 
                                            	  	<?=$newtaozhuang_list2[$a]["child"][$b]["typename"]?>
                                            	 </a>
                                            </span> 
  											<!-- 
  											<span style=" cursor:pointer;" id="upload_img<?=$newtaozhuang_list2[$a]["child"][$b]["id"]?>" onclick="javascript:window.open(<?="'".$url.$newtaozhuang_list2[$a]["child"][$b]["id"]."'"?> ,'width=800,height=600,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes')">上传图片</span> 
						 
  											 -->
                                            <?php for($c=0;$c<count($newtaozhuang_list2[$a]["child"][$b]["child"]);$c++):?>
                                            <ul>
                                                 <li style="display:none;">
                                                 	<!-- <input id='check_img(<?=$newtaozhuang_list2[$a]["child"][$b]["child"][$c]["id"]?>)' onclick='check_img(this,<?=$newtaozhuang_list2[$a]["child"][$b]["child"][$c]["id"]?>)' type="checkbox" value="<?=$newtaozhuang_list2[$a]["child"][$b]["child"][$c]["id"]?>" >
                                          -->
                                                    <span>
                                                        <i class="icon-leaf" style="background-image:none!important;" > </i>
                                                        <a href="#" onclick="getData3(1,<?=$newtaozhuang_list2[$a]["child"][$b]["child"][$c]["id"]?>,'type')">
                                                        	<?=$newtaozhuang_list2[$a]["child"][$b]["child"][$c]["typename"]?>
                                                        </a>
                                                    </span> 
                                                   <!-- 
                                                     <span style=" cursor:pointer;" id="upload_img<?=$newtaozhuang_list2[$a]["child"][$b]["child"][$c]["id"]?>" onclick="javascript:window.open(<?="'".$url.$newtaozhuang_list2[$a]["child"][$b]["child"][$c]["id"]."'"?>,'width=800,height=600,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes')">上传图片</span> 
		 										
                                                    -->
                                                   
                                                  </li>
                                             </ul>
                                         
                              				 <?php endfor;?>
                              				
 										</li>
            					<?php else:?>
            							<?php if(key_exists("typename", $newtaozhuang_list2[$a]["child"][$b])):?>
            										<li>
            											<!-- 	<input id='check_img(<?=$newtaozhuang_list2[$a]["child"][$b]["id"]?>)' onclick='check_img(this,<?=$newtaozhuang_list2[$a]["child"][$b]["id"]?>)' type="checkbox" value="<?=$newtaozhuang_list2[$a]["child"][$b]["id"]?>" >
                                       -->
                                						<span>
                                    						<i class="icon-leaf"></i>
                                    						 <a href="#" onclick="getData(1,<?=$newtaozhuang_list2[$a]["child"][$b]["id"]?>,'type')"> 
                                                        	  		<?=$newtaozhuang_list2[$a]["child"][$b]["typename"]?>
                                                        	 </a>
                                						 </span> 
                                						 <!-- 
                                						 		 <span style=" cursor:pointer;" id="upload_img<?=$newtaozhuang_list2[$a]["child"][$b]["id"]?>" onclick="javascript:window.open(<?="'".$url.$newtaozhuang_list2[$a]["child"][$b]["id"]."'"?> ,'width=800,height=600,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes')">上传图片</span> 
                                				
                                						  -->
                                					</li>
            					
            							<?php endif;?>
            						
            					<?php endif;?>

            				</ul>
            				<?php endfor;?>
            			</li>
            			 
            		</ul>
            		<?php endfor;?>
			</li>		
			</ul>
			<!-- 新算法结束 -->
		</li>
	   <!-- 新套装结束 -->
	   <!-- 秀家开始 -->
	   <li>
			<span><i class="icon-folder-open"></i><a href="#" onclick="getData(1,485,'type')">秀家</a></span> 
				<?php for($a=0;$a<count($xiujia_list2);$a++):?>
			<ul>
				<li>
					<span><i class="icon-minus-sign"></i>
					
					<a href="#" onclick="getData3(1,<?=$xiujia_list2[$a]["id"]?>,'type')"><?=$xiujia_list2[$a]["typename"]?></a>
					 </span> 
					 <!-- 
					  <span style=" cursor:pointer;" id="upload_img<?=$xiujia_list2[$a]["id"]?>" onclick="javascript:window.open(<?="'".$url.$xiujia_list2[$a]["id"]."'"?> ,'width=800,height=600,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes')">上传图片</span> 
                     
					  -->      
					<?php for($b=0;$b<count($xiujia_list2[$a]["child"]);$b++):?>
					<ul>
						
						<?php if(count($xiujia_list2[$a]["child"][$b]["child"])>0):?>
									<li>
											<!-- <input id='check_img(<?=$xiujia_list2[$a]["child"][$b]["id"]?>)' onclick='check_img(this,<?=$xiujia_list2[$a]["child"][$b]["id"]?>)' type="checkbox" value="<?=$xiujia_list2[$a]["child"][$b]["id"]?>" >
									 -->
											<span title="Collapse this branch" data-addr="<?=$xiujia_list2[$a]["child"][$b]["id"]?>">
											<i class="icon-minus-sign"></i>
											<a href="#" onclick="getData(1,<?=$xiujia_list2[$a]["child"][$b]["id"]?>,'type')"> 
												<?=$xiujia_list2[$a]["child"][$b]["typename"]?></span> 
											</a>
										</span> 
										
										<!-- 
										<span style=" cursor:pointer;" id="upload_img<?=$xiujia_list2[$a]["child"][$b]["id"]?>" onclick="javascript:window.open(<?="'".$url.$xiujia_list2[$a]["child"][$b]["id"]."'"?> ,'width=800,height=600,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes')">上传图片</span> 
					
									
										 -->
									<?php for($c=0;$c<count($xiujia_list2[$a]["child"][$b]["child"]);$c++):?>
									<ul>
											<li  >
												<!-- <input id='check_img(<?=$xiujia_list2[$a]["child"][$b]["child"][$c]["id"]?>)' onclick='check_img(this,<?=$xiujia_list2[$a]["child"][$b]["child"][$c]["id"]?>)' type="checkbox" value="<?=$xiujia_list2[$a]["child"][$b]["child"][$c]["id"]?>" >
									 -->
												<span>
												<i class="icon-leaf" style="background-image:none!important;" ></li>
													<a href="#" onclick="getData3(1,<?=$xiujia_list2[$a]["child"][$b]["child"][$c]["id"]?>,'type')">
														<?=$xiujia_list2[$a]["child"][$b]["child"][$c]["typename"]?>
													</a>
												
										</span>  
										<br/>
											<!-- 
												<span style=" cursor:pointer;" id="upload_img<?=$xiujia_list2[$a]["child"][$b]["child"][$c]["id"]?>" onclick="javascript:window.open(<?="'".$url.$xiujia_list2[$a]["child"][$b]["child"][$c]["id"]."'"?>,'width=800,height=600,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes')">上传图片</span> 
										
											 -->
											</li>
										</ul>
									
										<?php endfor;?>
									
								</li>
						<?php else:?>
									<?php if(key_exists("typename", $xiujia_list2[$a]["child"][$b]["child"])):?>
										<li>
										<!-- <input id='check_img(<?=$xiujia_list2[$a]["child"][$b]["id"]?>)' onclick='check_img(this,<?=$xiujia_list2[$a]["child"][$b]["id"]?>)' type="checkbox" value="<?=$xiujia_list2[$a]["child"][$b]["id"]?>" >
											 -->
											<span><i class="icon-leaf"></i> 
												<a href="#" onclick="getData(1,<?=$xiujia_list2[$a]["child"][$b]["id"]?>,'type')"> 
															<?=$xiujia_list2[$a]["child"][$b]["typename"]?>
												</a>     	 
											</span> 
										<!-- 
											<span style=" cursor:pointer;" id="upload_img<?=$xiujia_list2[$a]["child"][$b]["id"]?>" onclick="javascript:window.open(<?="'".$url.$xiujia_list2[$a]["child"][$b]["id"]."'"?> ,'width=800,height=600,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes')">上传图片</span> 
					
										 -->
										</li>
									<?php endif;?>
								
						
						<?php endif;?>

					</ul>
					<?php endfor;?>
				</li>
					
			</ul>
			<?php endfor;?>
         </li>
	    <!-- 秀家end -->
	    <!-- 老结构开始 -->
                <li>
                		<span>
                		<i class="icon-folder-open"></i>
                		<a  href="#" onclick="getData(1,-1,'type')">老结构</a> </span> 
                		 <?php for($a=0;$a<count($old_list2);$a++):?>
            		<ul>
            			<li>
            				<span><i class="icon-minus-sign"></i> 
                				<a href="#" onclick="getData(1,<?=$old_list2[$a]["id"]?>,'type')">  
                				 	<?=$old_list2[$a]["typename"]?>  
                				 </a>
            				 </span>
            				 
            				<!-- 
            				
            				 <span style=" cursor:pointer;" id="upload_img<?=$old_list2[$a]["id"]?>" onclick="javascript:window.open(<?="'".$url.$old_list2[$a]["id"]."'"?> ,'width=800,height=600,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes')">上传图片</span> 
						 
            				 -->
            				<?php for($b=0;$b<count($old_list2[$a]["child"]);$b++):?>
            				<ul>
            					
            					<?php if(count($old_list2[$a]["child"][$b]["child"])>0):?> 
            							 <li class="parent_li s" style="display:none;">
							 				<!--<input id='check_img(<?=$old_list2[$a]["child"][$b]["id"]?>)' onclick='check_img(this,<?=$old_list2[$a]["child"][$b]["id"]?>)' type="checkbox" value="<?=$old_list2[$a]["child"][$b]["id"]?>" >  -->
                                            <span title="Collapse this branch" data-addr="<?=$old_list2[$a]["child"][$b]["id"]?>">
                                            	<i class="icon-plus-sign"></i>
                                            	 <a href="#" onclick="getData(1,<?=$old_list2[$a]["child"][$b]["id"]?>,'type')"> 
                                            	  	<?=$old_list2[$a]["child"][$b]["typename"]?>
                                            	 </a>
                                            </span> 
  											<!-- 
  											
  											<span style=" cursor:pointer;" id="upload_img<?=$old_list2[$a]["child"][$b]["id"]?>" onclick="javascript:window.open(<?="'".$url.$old_list2[$a]["child"][$b]["id"]."'"?> ,'width=800,height=600,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes')">上传图片</span> 
						 
  											 -->
                                            <?php for($c=0;$c<count($old_list2[$a]["child"][$b]["child"]);$c++):?>
                                            <ul>
                                                 <li>
                                                 <!-- 	<input id='check_img(<?=$old_list2[$a]["child"][$b]["child"][$c]["id"]?>)' onclick='check_img(this,<?=$old_list2[$a]["child"][$b]["child"][$c]["id"]?>)' type="checkbox" value="<?=$old_list2[$a]["child"][$b]["child"][$c]["id"]?>" >
                                          -->
                                                    <span>
                                                        <i class="icon-leaf" style="background-image:none!important;" > </i>
                                                        <a href="#" onclick="getData3(1,<?=$old_list2[$a]["child"][$b]["child"][$c]["id"]?>,'type')">
                                                        	<?=$old_list2[$a]["child"][$b]["child"][$c]["typename"]?>
                                                        </a>
                                                    </span> 
                                                    
                                                   <!-- 
                                                     <span style="cursor:pointer;" id="upload_img<?=$old_list2[$a]["child"][$b]["child"][$c]["id"]?>" onclick="javascript:window.open(<?="'".$url.$old_list2[$a]["child"][$b]["child"][$c]["id"]."'"?>,'width=800,height=600,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes')">上传图片</span> 
		 										
                                                    -->
                                                  </li>
                                             </ul>
                                         
                              				 <?php endfor;?>
                              				
 										</li>
            					<?php else:?> 
            							<?php if(key_exists("typename", $old_list2[$a]["child"][$b])):?>
            										<li>
            										<!-- 	<input id='check_img(<?=$old_list2[$a]["child"][$b]["id"]?>)' onclick='check_img(this,<?=$old_list2[$a]["child"][$b]["id"]?>)' type="checkbox" value="<?=$old_list2[$a]["child"][$b]["id"]?>" >
                                					 -->
            											<span>
                                    						<i class="icon-leaf"></i>
                                    						 <a href="#" onclick="getData(1,<?=$old_list2[$a]["child"][$b]["id"].","?>'type')"> 
                                                        	  		<?=$old_list2[$a]["child"][$b]["typename"]?>
                                                        	 </a>
                                						 </span> 
                                						<!-- 
                                						 <span style="cursor:pointer;" id="upload_img<?=$old_list2[$a]["child"][$b]["id"]?>" onclick="javascript:window.open(<?="'".$url.$old_list2[$a]["child"][$b]["id"]."'"?> ,'width=800,height=600,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes')">上传图片</span> 
			
                                						 -->
                                					</li>
            					
            							<?php endif;?>
            						
            					<?php endif;?>

            				</ul>
            				<?php endfor;?>
            			</li>
            			 
            		</ul>
             <?php endfor;?>
                	</li>
            	<!-- 老结构结束 -->
            	<!-- 分类表开始 $cateList -->
            	  <li>
                		<span><i class="icon-folder-open"></i>
                		<a href="#" onclick="getData(1,-2,'type')">分类表</a></span> 
                			 <?php for($a=0;$a<count($cateList);$a++):?>
                            		<ul>
                            			<li>
                            				<span><i class="icon-minus-sign"></i> 
                            				<a href="#" onclick="getData(1,<?=$cateList[$a]['id']?>,'type')"><?=$cateList[$a]["typename"]?></a>
                            				</span> 
                            				<!-- 
                            				<span style=" cursor:pointer;" id="upload_img<?=$cateList[$a]["id"]?>" onclick="javascript:window.open(<?="'".$url.$cateList[$a]["id"]."'"?> ,'width=800,height=600,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes')">上传图片</span> 
                						 
                            				 -->
                            				<?php for($b=0;$b<count($cateList[$a]["child"]);$b++):?>
                            				<ul>
                            					
                            					<?php if(count($cateList[$a]["child"][$b]["child"])>0):?>
                            							 <li class="parent_li" style="display:none;">
                            							 <!-- 	<input id='check_img(<?=$cateList[$a]["child"][$b]["id"]?>)' onclick='check_img(this,<?=$cateList[$a]["child"][$b]["id"]?>)' type="checkbox" value="<?=$cateList[$a]["child"][$b]["id"]?>" >
                                                      -->
                							 			       <span title="Collapse this branch" data-addr="<?=$cateList[$a]["child"][$b]["id"]?>">
                                                            	<i class="icon-plus-sign"></i>
                                                            	 <a href="#" onclick="getData(1,<?=$cateList[$a]['child'][$b]['id']?>,'type')"> 
                                                            	  	<?=$cateList[$a]["child"][$b]["typename"]?>
                                                            	 </a>
                                                            </span> 
                  											<!-- 
                  											<span style=" cursor:pointer;" id="upload_img<?=$cateList[$a]["child"][$b]["id"]?>" onclick="javascript:window.open(<?="'".$url.$cateList[$a]["child"][$b]["id"]."'"?> ,'width=800,height=600,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes')">上传图片</span> 
                						 
                  											 -->
                                                            <?php for($c=0;$c<count($cateList[$a]["child"][$b]["child"]);$c++):?>
                                                            <ul>
                                                                 <li  >
                                                                 	<!-- <input id='check_img(<?=$cateList[$a]["child"][$b]["child"][$c]["id"]?>)' onclick='check_img(this,<?=$cateList[$a]["child"][$b]["child"][$c]["id"]?>)' type="checkbox" value="<?=$cateList[$a]["child"][$b]["child"][$c]["id"]?>" >
                                                          -->
                                                                    <span>
                                                                        <i class="icon-leaf" style="background-image:none!important;" > </i>
                                                                        <a href="#" onclick="getData(1,<?=$cateList[$a]['child'][$b]['child'][$c]['id'].","?>'type')">
                                                                        	<?=$cateList[$a]["child"][$b]["child"][$c]["typename"]?>
                                                                        </a>
                                                                    </span> 
                                                                  
                                                                    <!-- 
                                                                     <span style=" cursor:pointer;" id="upload_img<?=$cateList[$a]["child"][$b]["child"][$c]["id"]?>" onclick="javascript:window.open(<?="'".$url.$cateList[$a]["child"][$b]["child"][$c]["id"]."'"?>,'width=800,height=600,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes')">上传图片</span> 
                		 										
                                                                     -->
                                                                  </li>
                                                             </ul>
                                                         
                                              				 <?php endfor;?>
                                              				
                 										</li>
                            					<?php else:?>
                            							<?php if(key_exists("typename", $cateList[$a]["child"][$b])):?>
                            										<li>
                            										<!-- <input id='check_img(<?=$cateList[$a]["child"][$b]["id"]?>)' onclick='check_img(this,<?=$cateList[$a]["child"][$b]["id"]?>)' type="checkbox" value="<?=$cateList[$a]["child"][$b]["id"]?>" >
                                                					 -->
                            												<span>
                                                    						<i class="icon-leaf"></i>
                                                    						 <a href="#" onclick="getData(1,<?=$cateList[$a]["child"][$b]["id"].","?>'type')"> 
                                                                        	  		<?=$cateList[$a]["child"][$b]["typename"]?>
                                                                        	 </a>
                                                						 </span> 
                                                						<!-- 
                                                						
                                                						 <span style="cursor:pointer;" id="upload_img<?=$cateList[$a]["child"][$b]["id"]?>" onclick="javascript:window.open(<?="'".$url.$cateList[$a]["child"][$b]["id"]."'"?> ,'width=800,height=600,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes')">上传图片</span> 
                						 
                                                						 -->
                                                					</li>
                            					
                            							<?php endif;?>
                            						
                            					<?php endif;?>
                
                            				</ul>
                            				<?php endfor;?>
                            			</li>
                            			 
                            		</ul>
					<?php endfor;?>
                	</li>
 				<!-- 分类表结束 -->
		 </ul>	 
	
	<hr/>

</div>
<div>
<!-- 点击菜单 显示id  用于添加新类型，当点击到三级的菜单，设置id为0，判断id为0时 不可添加类型 -->
 <input type="hidden" id="show_img_id"/>
 
 <input  type="hidden" id="upload_img_typeid"/>
 <!-- 点击菜单显示id  用于删除类别  -->
 <input type="hidden" id="del_img_id"/>
</div>
<div style='border:1px solid #ccc;'>

<!--搜索图片  添加类型 等等图片操作-->
	<div id="operation_img">
		<span style='text-align:right;'><?=Html::textInput('search_image','',['id'=>'search_value','style'=>'width:200px;margin-top:10px;margin-left:50px;','placeholder'=>'图片名称']) ?>
		<?=Html::button('搜索图片',['onclick' => 'javascript:getData(1,$("#search_value").val(),"name")','class'=>'btn','style'=>'']) ?>
		</span>
		<button onclick="add_type()">添加新类型</button>  
		<button onclick="del_type()">删除类型</button>
		<button onclick="del_img()">删除选中图片</button>
		<button onclick="upload_img()">上传图片</button> 
		<!-- 秀家的编辑图片 -->
		<?php if($img_id>0):?>
		<input id="show_id" type="hidden" value="<?=$img_id?>"/>
		<button onclick="up_show_img()">选择/修改秀家底图</button>
		<button onclick="new_show_img()">添加底图秀家底图</button>
		<?php endif;?>
		<!-- vr的编辑图片 -->
		<?php if($tzid>0):?>
		<input id="vr_pos_id" type="hidden" value="<?=$vr_pos_id?>"/>
            <!-- type  1 添加主图  2 添加从图，需要获取pos -->
            <input id="type" type="hidden" value="<?=$type?>"/>
           <input id="tzid"  type="hidden" value="<?=$tzid?>"/>
        <button onclick="up_vrpos_img()">选择/修改vr底图</button>
        <button onclick="new_vrpos_img()">添加vr底图</button>
		<?php endif;?>
			
	</div>


	<!-- 添加新类型 div -->
	<div id="add_type_div" style="display: none;">
	添加新的类型：<input  id="new_addr" type="text" />
	类型显示名称：<input  id="new_typename" type="text"/>
	<button onclick="addtype_data()">添加</button>
	<button onclick="addtype_hide()">关闭</button>
	</div>
</div>
<!--图片显示div-->
<div id="list" style="text-align: center;">
	<ul>
	</ul>
</div>

<div id="pagecount"></div>



</body>

    	<style type="text/css">.tree {
    min-height:20px;
    padding:19px;
    margin-bottom:20px;
    background-color:#fbfbfb;
    border:1px solid #999;
    -webkit-border-radius:4px;
    -moz-border-radius:4px;
    border-radius:4px;
    -webkit-box-shadow:inset 0 1px 1px rgba(0, 0, 0, 0.05);
    -moz-box-shadow:inset 0 1px 1px rgba(0, 0, 0, 0.05);
    box-shadow:inset 0 1px 1px rgba(0, 0, 0, 0.05)
}
.tree li {
    list-style-type:none;
    margin:0;
    padding:0px 5px 0px 5px;
    position:relative
}
.tree li::before, .tree li::after {
    content:'';
    left:-20px;
    position:absolute;
    right:auto
}
.tree li::before {
    border-left:1px solid #999;
    bottom:50px;
    height:100%;
    top:0;
    width:1px
}
.tree li::after {
    border-top:1px solid #999;
    height:20px;
    top:25px;
    width:25px
}
.tree li span {
    -moz-border-radius:5px;
    -webkit-border-radius:5px;
    border:1px solid #999;
    border-radius:5px;
    display:inline-block;
    padding:1px 8px;
    text-decoration:none
}
.tree li.parent_li>span {
    cursor:pointer
}
.tree>ul>li::before, .tree>ul>li::after {
    border:0
}
.tree li:last-child::before {
    height:30px
}
.tree li.parent_li>span:hover, .tree li.parent_li>span:hover+ul li span {
    background:#eee;
    border:1px solid #94a0b4;
    color:#000
}


<!--list的-->
#list{width:680px; height:530px; margin:2px auto; position:relative} 
#list ul li{display:inline-block;width:240px; height:240px; margin:10px} 
 
#list ul li p{line-height:22px} 
#pagecount{width:500px; margin:10px auto; text-align:center;} 
#pagecount span{margin:4px; font-size:14px} 
#list ul li#loading{width:120px; height:32px; border:1px solid #d3d3d3; 
position:absolute; top:35%; left:42%; text-align:center; background:#f7f7f7
url(loading.gif) no-repeat 8px 8px;-moz-box-shadow:1px 1px 2px rgba(0,0,0,.2); 
-webkit-box-shadow:1px 1px 2px rgba(0,0,0,.2); box-shadow:1px 1px 2px rgba(0,0,0,.2);} 


ul{list-style:none;}

</style>
    	
<script>$(function () {
    $('.tree li:has(ul)').addClass('parent_li').find(' > span').attr('title', 'Collapse this branch');
	 $('.tree li.parent_li > span').live('click', function (e) {
        var children = $(this).parent('li.parent_li').find(' > ul > li');
        var parent=$(this).parent('li.parent_li');
        console.log($(this));
        if (children.is(":visible")) {
            children.hide('fast');
            $(this).attr('title', 'Expand this branch').find(' > i').addClass('icon-plus-sign').removeClass('icon-minus-sign');
        } else {
        	if(children.length==0){
        		var addr=$(this).data('addr');
        		var url = "index.php?r=image/upload-image&type_id=";
	        	$.ajax({
					url: 'index.php?r=image/child-tree',
					type: 'get',
					dataType: 'json',
					data: {addr:addr},
					success:function(res) {
						console.log(res);
						if(res.status==1){
							for(var i=0;i<res.data.length;i++){
					     		if(res.data[i].child=='true'){
					     			var html="<ul><li class='parent_li'><input id='check_img("+res.data[i].id+")' onclick='check_img(this,"+res.data[i].id+")' type='checkbox' value='"+res.data[i].id+"'/><span data-addr="+res.data[i].addr+"><i class='icon-plus-sign'></i><a href='javascript:;' onclick='getData(1,"+res.data[i].id+")'> "+res.data[i].typename+"</a></span><br/><span style='display:none;cursor:pointer;' id='upload_img"+res.data[i].id+"' onclick='javascript:window.open('"+url+res.data[i].id+"','','width=800,height=600,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes')'>上传图片</span><li></ul>";
					     				parent.append(html);
					     		}else{
					     			var html="<ul><li><input id='check_img("+res.data[i].id+")' onclick='check_img(this,"+res.data[i].id+")' type='checkbox' value='"+res.data[i].id+"'/><span><a href='javascript:;' onclick='getData(1,"+res.data[i].id+")'> "+res.data[i].typename+"</a></span><br/><span style='display:none;cursor:pointer;' id='upload_img"+res.data[i].id+"' onclick='javascript:window.open('"+url+res.data[i].id+"','','width=800,height=600,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes')'>上传图片</span><li></ul>";
					     				parent.append(html);
					     		}
					     	}
					     	children.show('fast');
            				$(this).attr('title', 'Collapse this branch').find(' > i').addClass('icon-minus-sign').removeClass('icon-plus-sign');
            				// bindtree();
						}
					},errror:function() {
						console.log("error");
					}
				})
        	}else{
        		children.show('fast');
            	$(this).attr('title', 'Collapse this branch').find(' > i').addClass('icon-minus-sign').removeClass('icon-plus-sign');
        	}
        }
        e.stopPropagation();

//test
//记录鼠标是否按下
/* var isMouseDown=false;
//获取鼠标刚按下时的位置
var offestX=0;
var offestY=0;

var i=0;
	 //获取div
   var div=document.getElementsByClassName("divs")[i];
   //鼠标按下事件,鼠标按下是相对div而言的
  div.onmousedown=function(e){
       isMouseDown=true;
       //记录鼠标刚按下时的位置，相对物体div而言
       offestX= e.offsetX;
       offestY= e.offsetY;
       console.log("鼠标按下时候:");
       console.log(offestX);
       console.log(offestY);

  }
   //鼠标移动，鼠标移动是相对于整个页面而言的，所以用document
  document.onmousemove=function(e){
       //如何鼠标没有按下就直接返回，不用执行下面的代码
       if(isMouseDown==false)return;
       var x=  e.pageX-offestX;
       var y=  e.pageY-offestY;
       console.log("鼠标移动  时候:");
       console.log(x);
       console.log(y);
       //修改单品显示在底图的位置
        div.style.left=x+"px"; 
       div.style.top=y+"px";
    }
   //鼠标抬起
    document.onmouseup=function(e){
      isMouseDown=false;
      var x=  e.pageX-offestX;
      var y=  e.pageY-offestY;
      div.style.left=x+"px"; 
      div.style.top=y+"px";
      console.log("鼠标按下时候:");
      //ajax修改pos数据
      var id=$("#img_id").val();
      if(id>0){
         	 $.ajax({'url':'index.php?r=show/up-pos',data:{'id':id,'x':x,'y':y},
               success(){
               //location.reload();
               }
           });
 		 }
      
    } */



        //test
    });
});</script>
	
<!-- Generated by RunJS (Mon Nov 30 11:35:25 CST 2015) 0ms -->